package cn.doitedu.javase.io;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class _08_InputStreamReader和InputStreamWriter基本api示例 {

    public static void main(String[] args) throws IOException {

        // 1. 先构造一个基础字节流
        FileOutputStream fileOutputStream = new FileOutputStream("e:/p.txt", false);
        // 2. 将基础字节流，包装成一个OutputStreamWriter
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, StandardCharsets.UTF_8);
        // 3. 调用write方法输出
        outputStreamWriter.write("哈哈哈哈\n");
        outputStreamWriter.write("哈哈哈哈\n");

        outputStreamWriter.flush();
        outputStreamWriter.close();

        // 1.先构造一个字节输入流
        FileInputStream fis = new FileInputStream("e:/p.txt");
        // 2.然后将字节输入流，包装成字符流
        InputStreamReader reader = new InputStreamReader(fis);
        // 3.调用read方法读数据

        char[] chars = new char[10];
        int read = reader.read(chars);

        reader.close();

    }
}
